#include "sys.h"
#include "ds1302.h"

u8 timeMode,clockMode,showMode;
TIME clock;
void key_action()
{
	if(S7 == 0)
	{
		showMode = 0;
		delay1ms(5);
		while(!S7);
		Ds1302_Single_Byte_Write(ds1302_sec_addr,0x80);
		timeMode++;
		timeMode &= 0x03;
		if(timeMode == 0)
		{
			Ds1302_setTime(&time);
		}
	}	
	if(S6 == 0)
	{
		showMode = 1;
		delay1ms(5);
		while(!S6);	
		clockMode++;
		clockMode &= 0x03;
	}
	
	if(S5 == 0)
	{
		delay1ms(5);
		while(!S5);
		switch(showMode)
		{
			case 0:
				switch(timeMode)
				{
					case 0:break;
					case 1:time.hour++;if(time.hour == 24) time.hour = 0;
					case 2:time.min++; if(time.min == 60)   time.min = 0;
					case 3:time.sec++; if(time.sec == 60)   time.sec = 0;
				}break;
			case 1:
				switch(clockMode)
				{
					case 0:break;
					case 1:clock.hour++;if(clock.hour == 24) clock.hour = 0;break;
					case 2:clock.min++; if(clock.min == 60) clock.min = 0;break;
					case 3:clock.sec++; if(clock.sec == 60) clock.sec = 0;break;
				}break;	
		}
	}
	if(S4 == 0)
	{
		delay1ms(5);

		while(!S4);
		switch(showMode)
		{
			case 0:
				switch(timeMode)
				{
					case 0:break;
					case 1:time.hour--;if(time.hour < 0) time.hour = 0;break;
					case 2:time.min--; if(time.min < 0)   time.min = 0;break;
					case 3:time.sec--; if(time.sec < 0)   time.sec = 0;break;
				}break;
			case 1:
				switch(clockMode)
				{
					case 0:break;
					case 1:clock.hour--;if(clock.hour < 0) clock.hour = 0;break;
					case 2:clock.min--; if(clock.min < 0) clock.min = 0;break;
					case 3:clock.sec--; if(clock.sec < 0) clock.sec = 0;break;
				}break;	
		}
	
	}
}

